package com.xueyiyue.xueyiyue.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xueyiyue.xueyiyue.model.entity.NewsListVo;
import com.xueyiyue.xueyiyue.model.entity.QicheChoujiang;
import com.xueyiyue.xueyiyue.model.entity.QicheChoujiangList;
import com.xueyiyue.xueyiyue.model.entity.QicheNewsList;
import com.xueyiyue.xueyiyue.model.sys.ApiResult;
import com.xueyiyue.xueyiyue.service.QicheService;
import com.xueyiyue.xueyiyue.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenlixian
 * @description TODO
 * @date 2021/4/4 13:38
 */
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/qiche")
public class QicheController {
    @Autowired
    private QicheService qicheService;
    /**
     * @return
     */
    @GetMapping("/getNewsList")
    public ApiResult getNewsList(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<QicheNewsList> list = qicheService.getNewsList();
        PageInfo<QicheNewsList> pageInfo = new PageInfo<QicheNewsList>(list);
        return ApiResult.ok(pageInfo);

    }
    /**抽奖活动查询
     * @return
     */
    @GetMapping("/getChoujiangInfo")
    public ApiResult getChoujiangInfo(@RequestParam("id") Long id) {
        QicheChoujiang qicheChoujiang = qicheService.getChoujiangInfo(id);
        return ApiResult.ok(qicheChoujiang);

    }
    /**抽奖活动名单
     * @return
     */
    @GetMapping("/getChoujiangList")
    public ApiResult getChoujiangInfo() {
        List<QicheChoujiangList> list = qicheService.getChoujiangList();
        return ApiResult.ok(list);

    }
    @GetMapping("/finishChoujiang")
    public ApiResult finishChoujiang(@RequestParam("id") Long id) {
        Integer count = qicheService.finishChoujiang(id);
        return ApiResult.ok(count);

    }
    @PostMapping("/updateList")
    public ApiResult updateList(@RequestBody QicheChoujiangList winner) {
        Integer count = qicheService.updateList(winner);
        return ApiResult.ok(count);

    }
    @GetMapping("/addPhone")
    public ApiResult addPhone(@RequestParam("phone") String phone) {
        try{
        Integer count = qicheService.addPhone(phone);}
        catch (Exception e){
            return ApiResult.ok(1);
        }
        return ApiResult.ok(1);

    }

}